# Author: Mr.Xu
# @Time : 2019/12/4 20:03
from rest_framework import serializers

from . import models

class TeacherModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Teacher
        fields = (
            'name',
            'role_name',
            'title',
            'signature',
            'image',
            'brief',
        )

class FreeCourseModelSerializer(serializers.ModelSerializer):
    teacher = TeacherModelSerializer()
    class Meta:
        model = models.Course
        fields = [
            "id",
            "name",
            "course_img",
            "brief",
            "level_name",
            "period",
            "students",
            "sections",
            "price",
            "teacher",
            "course_category",
            'section_list',
            "teacher",
        ]

class CategoryModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseCategory
        fields = ('id', 'name')

class CourseSectionModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseSection
        fields = '__all__'

class CourseChapterModelSerializer(serializers.ModelSerializer):
    # 子序列化
    coursesections = CourseSectionModelSerializer(many=True)
    class Meta:
        model = models.CourseChapter
        fields = (
            'id',
            'name',
            'chapter',
            'summary',
            'coursesections',
        )